package com.k.base.jdk.stream;

import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        for(int i=0;i<10;i++){
            set.add(""+i);
        }
        List<String> list = new ArrayList(set);
        //list.addAll(set);
        System.out.println(list.stream().filter(a->a.equals("aa")).map(b->b).collect(Collectors.toSet()));
    }

    private static Map<Integer,List<String>> pageResultMap(List<String> list, int pageSize){
        Map<Integer,List<String>> map = new HashMap<>();
        long totalPage = pageCount(list.size(),pageSize);
        System.out.println("totalPage:"+totalPage);
        List<String> listZ = new ArrayList();
        for(int i=1;i<=totalPage;i++){
            List<String> itmList = pageList(list,i,pageSize);
            map.put(i,itmList);
        }
        return map;
    }

    /**
     * 获取总页数
     * @param total 总记录数
     * @param pageSize 每页显示记录数
     * @return result
     */
    private static long pageCount(int total,int pageSize){
        return  (total % pageSize > 0 ? 1 : 0) + (total / pageSize);
    }

    /**
     * 获取分页数据
     * @param list list
     * @param pageNo 页码
     * @param pageSize 每页数量
     */
    private static List<String> pageList(List<String> list,long pageNo, long pageSize){
        long offset = pageNo < 1? 0L: (pageNo - 1) * pageSize;
        return list.stream()
                .skip(offset)
                .limit(pageSize)
                .collect(Collectors.toList());
    }
}
